// pages/visaInfo/visaInfo.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');

var app = getApp();
Page({

  /**
   * 页面的初始数据 
   */
  data: {

    movies: [
      {
        url: 'https://swcj.majiangyun.com/img/ioc/vist-detail.png',
      }
    ], article:{},
    setMeal: [
      '签证费+服务费',
      '签证费+服务费+加急费',
      '签证费+服务费+拒签退款(附条件)+优质客户简化材料',
      '签证费+服务费+拒签退款(附条件)+6工作日加急办理',
      '签证费+服务费+拒签退款(附条件)+5工作日加急办理'
    ],
    clickId: 0,
    clickItem: '签证费+服务费',
    flag: true,
    num:true,
    goods:{},
    list:[],
    text1:{},
    article1:{},
    text2:{},
    userInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (model) {
    var that = this;
    var userInfo = util.getKey("userInfo");
    that.setData({
      userInfo: userInfo
    })
    //商品信息
    that.getModel(model.id);

  
  },
  //获取列表
  getModel: function (id) {
    var that = this;
    httpUtil.getHttp("/goods_travel/get/" + id + "?userId=" + that.data.userInfo.id, {}, function (res) {
      if (res.urlList == null || res.urlList==[]){
        res.urlList = [res.url];
      }
      if (res.goodsType==0){
        wx.redirectTo({
          url: '../visaInfo/visaInfo?id=' + res.id
        })
      }
      let data = app.towxml.toJson(res.text, 'markdown');
      let da = app.towxml.toJson(res.strokeText, 'markdown');
      let text1 = app.towxml.toJson(res.preText, 'markdown');
      let text2 = app.towxml.toJson(res.refundText, 'markdown');
      
      var text="门票";
      switch (res.goodsType){
        case 0: text = "签证"; break;
        case 1: text = "当地玩乐"; break;
        case 2: text = "跟团游"; break;
        case 3: text = "自由行"; break;
        default:text="门票";
      }
      wx.setNavigationBarTitle({
        title: text,
      }) 
      that.getList(res.goodsType, res.id);

      that.setData({
        goods: res,
        article:data,
        article1: da,
        text1: text1,
        text2: text2
      })
    })
  },
  getList:function(type,id){
    var that=this;
    httpUtil.getHttp("/goods_travel/list?type=" + type+"&id="+id,{},function(res){
      that.setData({
        list:res
      })
    })
  }, linkMore: function (e) {
    var id = e.target.dataset.id;
    console.log(id);
    wx.redirectTo({
      url: '../proInfo/proInfo?id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selActive: function (res) {
    var that = this;
    that.setData({
      clickId: res.currentTarget.dataset.id
    })
  },
  clickSure: function () {
    var that = this;
    that.setData({
      flag: true
    })
  },
  showMeal: function () {
    var that = this;

    that.setData({
      flag: false
    })

  },
  evalDetail:function(e){
    var id=e.target.dataset.id;
    var type=e.target.dataset.type;
    wx.navigateTo({
      url: '../evaluate/evaluate?id='+id+"&type="+type
    })
  },
  addShop:function(){
    wx.showToast({
      title: '添加成功',
      icon: 'success',
      duration: 2000
    })
    var that = this;
    that.setData({
      num: false
    })
  },
  buyNow:function(){
    wx.navigateTo({
      url: '../reserve/reserve'
    })
  },
  showShopCar:function(){
    wx.switchTab({
      url: '../shopCar/shopCar'
    }) 
  }
})